package com.example.demo.view;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.bean.SysUser;

import io.swagger.annotations.Api;

@RestController
@Api
public class LoginController {
        
        private final Logger log = LoggerFactory.getLogger(this.getClass());
        @Autowired
        private SysUserMapper sysUserMapper;
        @RequestMapping(value="/login",method=RequestMethod.GET)
        private  ModelAndView login( SysUser user,ModelAndView model){
                model.setViewName("login");
                return model;
        }
        
        @RequestMapping(value="/login",method=RequestMethod.POST)
        private  ModelAndView login_post( SysUser user,ModelAndView model,String account_,String password_){
                SysUser  sysUser = sysUserMapper.queryLogin(user.getAccount_());
                if(user.getPassword_().equals(sysUser.getPassword_())){
                        model.setViewName("/home");
                }else{
                        model.addObject("user", user);
                        model.setViewName("/login");
                }
                return model;
        }
        

        @RequestMapping(value="/about",method=RequestMethod.GET)
        private  ModelAndView aboutPage( SysUser user,ModelAndView model){
                model.setViewName("front-blogs/about");
                return model;
        }
        @RequestMapping(value="/contact",method=RequestMethod.GET)
        private  ModelAndView contactPage( SysUser user,ModelAndView model){
                model.setViewName("front-blogs/contact");
                return model;
        }
        @RequestMapping(value="/blog",method=RequestMethod.GET)
        private  ModelAndView blogPage( SysUser user,ModelAndView model){
                model.setViewName("front-blogs/blog");
                return model;
        }
        
        @RequestMapping(value="/",method=RequestMethod.GET)
        private  ModelAndView indexPage( SysUser user,ModelAndView model){
                model.setViewName("front-blogs/index");
                return model;
        }
        
        @RequestMapping(value="/home",method=RequestMethod.GET)
        private  ModelAndView homePage( SysUser user,ModelAndView model){
                model.setViewName("front-blogs/index");
                return model;
        }
        
}
